<template>

  <div style="padding:10px ">
<!--    <div style="margin: 10px 0">-->
<!--      <el-button type="success" plain icon="el-icon-check" @click="add">添加学生信息</el-button>-->
<!--    </div>-->
    <div style="margin: 10px 0">
      <el-input v-model="search" placeholder="请输入学生姓名" style="width:20%" clearable></el-input>
      <el-button type="primary" plain icon="el-icon-search" @click="load">查询</el-button>
      <el-button type="success" plain icon="el-icon-check" @click="add">添加学生信息</el-button>
      <el-button type="primary" plain icon="el-icon-star-off" @click="createremark">生成评语</el-button>
    </div>
    <el-table
      :data="tableData"
      stripe
      style="width: 100%">
<!--  增加sid    -->
      <el-table-column
        prop="sid"
        label="学号"
      >
<!--  增加sid      -->
      </el-table-column>
      <el-table-column
        prop="name"
        label="姓名"
      >
      </el-table-column>
      <el-table-column
        prop="virtue"
        label="品德"
      >
      </el-table-column>
      <el-table-column
        prop="intelligence"
        label="智力"
      >
      </el-table-column>
      <el-table-column
        prop="sports"
        label="体育"
      >
      </el-table-column>
      <el-table-column
        prop="art"
        label="美术"
      >
      </el-table-column>
      <el-table-column
        prop="labor"
        label="劳动"
      >
      </el-table-column>
      <el-table-column
        prop="remark"
        label="评语"
        show-overflow-tooltip>
      </el-table-column>
      <el-table-column
        fixed="right"
        label="操作"
        width="100%">
        <template slot-scope="scope">
          <el-button @click="handleEdit(scope.row)" type="text" icon="el-icon-edit"  size="small">编辑</el-button>
          <el-button type="text" icon="el-icon-delete"  size="small" @click="handleDelete(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin:10px 0">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>

      <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
        <el-form :model="form" label-width="120px" :rules="rules">
          <el-form-item label="学号">
            <!--  增加sid      -->
            <el-input v-model="form.sid" prop="id" placeholder="请输入学生学号"></el-input>
<!--            <el-input v-model="form.id"></el-input>-->
          </el-form-item>
          <el-form-item label="学生名称">
            <el-input v-model="form.name" prop="name" placeholder="请输入学生姓名"></el-input>
          </el-form-item>
          <el-form-item label="德育分数">
            <el-input v-model="form.virtue" prop="virtue" placeholder="请输入学生德育分数"></el-input>
          </el-form-item>
          <el-form-item label="智育分数">
            <el-input v-model="form.intelligence" prop="intelligence" placeholder="请输入学生智育分数"></el-input>
          </el-form-item>
          <el-form-item label="体育分数">
            <el-input v-model="form.sports" prop="sports" placeholder="请输入学生体育分数"></el-input>
          </el-form-item>
          <el-form-item label="美育分数">
            <el-input v-model="form.art" prop="art" placeholder="请输入学生美育分数"></el-input>
          </el-form-item>
          <el-form-item label="劳育分数">
            <el-input v-model="form.labor" prop="labor" placeholder="请输入学生劳育分数"></el-input>
          </el-form-item>
          <el-form-item label="评价">
            <el-input type="textarea" v-model="form.remark"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="save_get">确 定</el-button>
  </span>
      </el-dialog>
      <el-dialog title="提示" :visible.sync="dialogVisible1" width="30%">
        <el-form :model="form" label-width="120px">
          <el-form-item label="学号">
            <el-input v-model="form.sid"></el-input>
          </el-form-item>
          <el-form-item label="学生名称">
            <el-input v-model="form.name"></el-input>
          </el-form-item>
          <el-form-item label="品德分数">
            <el-input v-model="form.virtue"></el-input>
          </el-form-item>
          <el-form-item label="智力分数">
            <el-input v-model="form.intelligence"></el-input>
          </el-form-item>
          <el-form-item label="体育分数">
            <el-input v-model="form.sports"></el-input>
          </el-form-item>
          <el-form-item label="美术分数">
            <el-input v-model="form.art"></el-input>
          </el-form-item>
          <el-form-item label="劳动分数">
            <el-input v-model="form.labor"></el-input>
          </el-form-item>
          <el-form-item label="评价">
            <el-input type="textarea" v-model="form.remark"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible1 = false">取 消</el-button>
    <el-button type="primary" @click="edit_get">确 定</el-button>
  </span>
      </el-dialog>

    </div>
  </div>
</template>

<script>

import request from "@/utils/re_request"
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name:"Home",
  data(){
    return{
      form:{},
      dialogVisible:false,
      dialogVisible1:false,
      search:'',
      currentPage:1,
      total:0,
      pageSize:10,
      tableData:[
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
        {
          id: '2018083056',
          name: '001',
          virtue:100,
          intelligence:100,
          sports:100,
          art:100,
          labor:100,
          remark: '评语内容'
        },
      ],
      tid:1,
      rules:{
        id:[
          {required: true, message: '请输入学生学号', trigger: 'blur'}
        ],
        name:[
          {required: true, message: '请输入学生姓名', trigger: 'blur'}
        ],
        virtue:[
          {required: true, message: '请输入德育成绩', trigger: 'blur'}
        ],
        intelligence:[
          {required: true, message: '请输入智育成绩', trigger: 'blur'}
        ],
        sports:[
          {required: true, message: '请输入体育成绩', trigger: 'blur'}
        ],
        art:[
          {required: true, message: '请输入美育成绩', trigger: 'blur'}
        ],
        labor:[
          {required: true, message: '请输入劳育成绩', trigger: 'blur'}
        ],
      },
    }
  },
  created(){
    this.load()
  },
  methods: {
    load(){
      request.get("/student",{
        params:{
          pageNum:this.currentPage,
          pageSize:this.pageSize,
          search:this.search
        }
      }).then(res =>{
        console.log(res)
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    save(){
      request.post("/student",this.form).then(res => {
        console.log(res)
        this.$message({
          type:"success",
          message:"学生新增成功！"
        })
        setTimeout(this.load,2000)
        this.dialogVisible=false
      })
    },
    save_get(){
      request.get("/student/save_get",{
        params:{
          sid:this.form.sid,
          name:this.form.name,
          virtue:this.form.virtue,
          intelligence:this.form.intelligence,
          sports:this.form.sports,
          art:this.form.art,
          labor:this.form.labor,
          remark:this.form.remark,
          tid:this.tid
        }
      }).then(res =>{
        console.log(123)
        console.log(res)
        console.log(456)
        this.$message({
          type:"success",
          message:"学生信息增加成功！"
        })
      })
      this.dialogVisible = false
      setTimeout(this.load,2000)
    },
    edit(){
      request.put("/student",this.form).then(res => {
        console.log(res)
        this.$message({
          type:"success",
          message:"Success!"
        })
      })
      this.dialogVisible1=false
      this.load()
    },
    edit_get(){
      console.log("edit_get start")
      console.log(this.form)
      request.get("/student/edit_get",{
        params:{
          //改
          sid:this.form.sid,
          //改
          id:this.form.id,
          name:this.form.name,
          virtue:this.form.virtue,
          intelligence:this.form.intelligence,
          sports:this.form.sports,
          art:this.form.art,
          labor:this.form.labor,
          remark:this.form.remark,
          tid:this.tid
        }
      }).then(res =>{
        console.log(res)
        this.$message({
          type:"success",
          message:"学生信息修改成功！"
        })
      })
      this.dialogVisible1 = false
      setTimeout(this.load,100)
    },
    add(){
      this.dialogVisible=true
      this.form = {}
    },
    handleEdit(row){
      this.form = JSON.parse(JSON.stringify(row))
      this.dialogVisible1 = true
    },
    handleSizeChange(pageSize){
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum){
      this.currentPage = pageNum
      this.load()
    },
    handleDelete(id){
      console.log(id)
      request.delete("/student/"+id).then(res =>{
        if(res.code === 0){
          this.$message({
            type:"success",
            message:"学生信息删除成功！"
          })
        }
        this.load()
      })
      request.get("/feedback/deletefeedback",{
        params:{
          id:id
        }
      })
      console.log("发出get请求")
    },
    createremark(){
      this.$message({
        type:"success",
        message:"开始生成评语，请耐心等待"
      })
      console.log(this.tid)
      request.get("/student/allremark",{
        params:{
          tid:this.tid
        }
      }).then(res =>{
      })
      this.load()
    }
  },
}
</script>

<style>

</style>
